﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.ServiceModel.Configuration;

namespace Cherry.Agile.ServiceModel.Interceptor
{
    /// <summary>
    /// 异常Behavior配置
    /// <example>
    /// <![CDATA[
    ///   <behaviors>
    ///     <serviceBehaviors>
    ///         <behavior name="exceptionHandling">
    ///             <exceptionHandling exceptionPolicy="myExceptionPolicy" />
    ///         </behavior>
    ///     </serviceBehaviors>
    ///   </behaviors>
    ///<extensions>
    ///     <behaviorExtensions>
    ///         <add name="exceptionHandling" type="Cherry.Agile.ServiceModel.Interceptor.ExceptionHandlingBehaviorElement, Cherry.Agile.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    ///     </behaviorExtensions>
    ///<extensions>
    /// ]]>
    /// </example>
    /// </summary>
    public class ExceptionHandlingBehaviorElement : BehaviorExtensionElement
    {
        /// <summary>
        /// 异常策略名称
        /// </summary>
        [ConfigurationProperty("exceptionPolicy")]
        public string ExceptionPolicy
        {
            get
            { return this["exceptionPolicy"] as string; }
            set
            { this["exceptionPolicy"] = value; }
        }
        
        /// <summary>
        /// 类型
        /// </summary>
        public override Type BehaviorType
        {
            get { return typeof(ErrorHandlingInterceptorAttribute); }
        }

        /// <summary>
        /// 构建Behavior
        /// </summary>
        /// <returns></returns>
        protected override object CreateBehavior()
        {
            return new ErrorHandlingInterceptorAttribute(this.ExceptionPolicy);
        }
    }
}


